<template>
  <div style="background: #fff">
    <div class="title">
      <div>{{ title }}</div>
    </div>
    <div >
      <el-form :inline="true">
      
         <!-- <el-form-item label="显示模块">
          <el-select v-model="query.type" placeholder="请选择"  clearable>
            
            <el-option
              v-for="item in type"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        -->
    
        <el-form-item>
          <!-- <el-button type="success" @click="getData(true)">查询</el-button> -->
          <!-- <el-button @click="reset">重置</el-button> -->
           <el-form-item style="text-align:right">
          <el-button type="primary" @click="showEdit(false)">添加</el-button>
        </el-form-item>
          <!-- <el-button type="primary" @click="showEdit(-1)">添加</el-button> -->
        </el-form-item>
      </el-form>
      
    </div>
     
    <el-table
      :data="data"
      stripe
      style="width: 100%; margin-bottom: 1.875rem"
    
    >
      </el-table-column>
      <el-table-column prop="id" label="id"></el-table-column>
      <el-table-column prop="name" label="导航名称"></el-table-column>
       <el-table-column prop="path" label="跳转链接"></el-table-column>
          <el-table-column prop="sort" label="排序数字越大越靠前"></el-table-column>
      <el-table-column label="封面" >
          <template slot-scope="scope">
            <el-image
              :src="
                cdn+scope.row.cover +
                '?imageView2/1/w/200/h/100/format/webp/q/75|imageslim'
              "
              style="width:50px;height:50px"
              :preview-src-list="[cdn+scope.row.cover]"
            >
            </el-image>
          </template>
        </el-table-column>
       
       <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="small" @click="showEdit(scope.row)">编辑</el-button>
          <el-button size="small" @click="del(scope.row)">删除</el-button>
        </template>
      </el-table-column>
     
    </el-table>
    

    <el-dialog title="编辑" :visible.sync="editModal" width="40%" :close-on-click-modal='false'>
        <el-form :model="item">
         <el-form-item label="标题">
            <el-input v-model="item.name" autocomplete="off" clearable></el-input>
          </el-form-item>
           <el-form-item label="链接">
            <el-input v-model="item.path" autocomplete="off" clearable></el-input>
          </el-form-item>
           <!-- <el-form-item label="显示模块">
          <el-select v-model="item.type" placeholder="请选择"  clearable>
            
            <el-option
              v-for="item in type"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item> -->
         <el-form-item label="封面">
          <div style="display: flex" >
            <div 
              class="demo-upload-list"
              v-for="(item, index) in [item.cover]"
              :key="index"
            >
              <template v-if="item">
                <img
                  :src="
                    cdn +
                    item +
                    '?imageView2/1/w/200/h/100/format/webp/q/75|imageslim'
                  "
                />
                <div class="demo-upload-list-cover">
                  <i
                    class="el-icon-view icon"
                    @click="preview(item, index,false)"
                  ></i>
                </div>
              </template>
            </div>

            <el-upload
              class="avatar-uploader"
              action="http://upload.qiniup.com"
              :show-file-list="false"
              :on-success="uploadCover"
              :data="qnToken"
            >
              <i class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
          </div>
        </el-form-item>
          <el-form-item label="排序">
            <el-input v-model="item.sort" autocomplete="off" clearable></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="editModal = false">取 消</el-button>
          <el-button type="primary" @click="edit">确 定</el-button>
        </div>
      </el-dialog>
  
  </div>
</template>

<script>
import mixin from "../../js/mixin";

export default {
  name: "nav",
  mixins: [mixin],
  data() {
    return {
      is_page: false,
      api_url: "nav",
      query: {
          type:1,
      },
      type:[
          {id:1,name:'公众号'},{id:2,name:'小程序'}
      ]
    };
  },
  components: {},
  mounted() {},
  created() {
    this.title = this.$route.meta.title;
    this.init();
  },
  methods: {
    init() {
      this.getArea();
      this.getQnToken();
      this.getData();
    },

    showEdit(e) {
      if (e) {
        this.item = e;
      } else {
        this.item = {
          cover: "",
        };
      }
      this.editModal = true;
    },
  },
};
</script>

<style scoped>
</style>
